package com.minelx.datamicroscope.core.query;

import com.minelx.datamicroscope.core.index.IndexFactory;
import com.minelx.hellopandas.core.PandasMethodProvider;
import io.gitee.minelx.filesystem.Directory;
import io.gitee.minelx.filesystem.TempPath;
import io.gitee.minelx.filesystem.provider.FSRegistry;

public class ResourcesFactory {

	private final FSRegistry fsRegistry;

	private final IndexFactory indexFactory;

	private final Directory storedCluesDirectory;

	private final Directory storedCachedIdentitiesDirectory;

	private final PandasMethodProvider pandasMethodProvider;

	public ResourcesFactory(FSRegistry fsRegistry,
							IndexFactory indexFactory,
							Directory storedCluesDirectory,
							Directory storedCachedIdentitiesDirectory,
							PandasMethodProvider pandasMethodProvider) {
		this.fsRegistry = fsRegistry;
		this.indexFactory = indexFactory;
		this.storedCluesDirectory = storedCluesDirectory;
		this.storedCachedIdentitiesDirectory = storedCachedIdentitiesDirectory;
		this.pandasMethodProvider = pandasMethodProvider;
	}

	QueryEmitter createEmitter(Resources resources) {
		return new QueryEmitter(resources, indexFactory, new RawConditionFactory(fsRegistry));
	}

	Resources makeResources(ResourceMapping rootResourceMapping) {
		return Resources.startWith(
				storedCluesDirectory,
				storedCachedIdentitiesDirectory,
				pandasMethodProvider,
				rootResourceMapping);
	}

	static ResourcesFactory localFSWithGeneralIndex() {
		return new ResourcesFactory(
				Query.onlyLocalFSRegistry(),
				IndexFactory.onlineIndexAndLocalStoredPandasFile(),
				TempPath.tempFileDirectoryAtWorkingDir(),
				TempPath.tempFileDirectoryAtWorkingDir(),
				Query.localPandas());
	}
}
